package br.com.sadim.diagnostico;

import java.io.Serializable;
import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@FacesConverter(forClass=Doenca.class)
public class DoencaConverter implements Converter {
	private DoencaRN doencaRN = new DoencaRN();
	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String string) {
		System.out.println("ProdutoConverter.getAsObject(): " + string);
		if(string == null || string.isEmpty()){
			return null;
		}
		return doencaRN.getById(Integer.valueOf(string));
	}
 
	@Override
	public String getAsString(FacesContext context, UIComponent component, Object object) {
		Doenca doenca = (Doenca) object;
		System.out.println("ProdutoConverter.getAsString(): " + doenca);
		if(doenca == null || doenca.getIdDoenca() == null){
			return null;
		}
		return String.valueOf(doenca.getIdDoenca());
	}
}